import { queryPageDataReq, toggleStateReq } from "./services";
import { namespace } from "./configFile";
import { message } from "antd";

export default {
  namespace,
  state: {
    init: false,
    data: [],
  },
  effects: {
    *pageInit({ params }, { call, put }) {
      const data = yield call(queryPageDataReq, params);
      if (data) {
        yield put({
          type: "save",
          payload: {
            data,
          },
        });
      }
    },

    *toggleState({ params, callback }, { call }) {
      let res = yield call(toggleStateReq, params);
      if (res) {
        callback && callback();
      }
    },
  },
  reducers: {
    save(state: any, { payload }: any) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
